/**
 * BinaryFormatter
 *
 * @author Chris Pratt
 *
 * 5/8/2010
 */
package com.anodyzed.onyx.text;

import com.anodyzed.onyx.util.Base64;
import com.anodyzed.onyx.util.Hex;

public class BinaryFormatter extends TextFormatter {
  private String style;

  /**
   * Constructor
   *  
   * @param parent The Parent TextFormat 
   * @param key The Argument Index or Map Key for this node 
   * @param bean The additional Bean reference String 
   */
  public BinaryFormatter (TextFormat parent,CharSequence key,CharSequence bean) {
    super(parent,key,bean);
    style = "dump";
  } //BinaryFormatter

  /**
   * Constructor
   *  
   * @param parent The Parent TextFormat 
   * @param key The Argument Index or Map Key for this node 
   * @param bean The additional Bean reference String 
   * @param style The Date Style
   */
  public BinaryFormatter (TextFormat parent,CharSequence key,CharSequence bean,CharSequence style) {
    super(parent,key,bean);
    this.style = style.toString();
  } //BinaryFormatter

  /**
   * Return a string representation of a date object
   *
   * @param args The Formatting Arguments
   * @return The Formatted String
   */
  @Override
  public String toString (Object... args) {
    Object o = getValue(args);
    if(o instanceof byte[]) {
      if(style.equals("dump")) {
        return Hex.dump((byte[])o);
      } else if(style.equals("base64")) {
        return Base64.encode((byte[])o);
      }
    } else if(o instanceof String) {
      if(style.equals("dump")) {
        return Hex.dump((String)o);
      }
    }
    return null;
  } //toString

} //*BinaryFormatter
